#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int t;
string x,a,b;
int cnt[100];

int main()
{
	cin>>t;
	while(t--)
	{
		memset(cnt, 0, sizeof cnt);
		cin>>a>>x>>b;
		int len = x.size();
		for(int i = 0;i < len;i++)
			cnt[x[i]]++;
		printf("%d*%c\n",*max_element(cnt+'A',cnt+'Z'+1),max_element(cnt+'A',cnt+'Z'+1)-cnt);
	}
    return 0;
}

